from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-03 14:16:39.954756
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 03, Oct, 2022
Time: 14:16:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5904
Nobs: 798.000 HQIC: -50.9156
Log likelihood: 10295.5 FPE: 6.30268e-23
AIC: -51.1185 Det(Omega_mle): 5.63442e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298941 0.053000 5.640 0.000
L1.Burgenland 0.108670 0.035624 3.050 0.002
L1.Kärnten -0.106487 0.018958 -5.617 0.000
L1.Niederösterreich 0.209065 0.074474 2.807 0.005
L1.Oberösterreich 0.101489 0.071527 1.419 0.156
L1.Salzburg 0.252519 0.037986 6.648 0.000
L1.Steiermark 0.037414 0.049700 0.753 0.452
L1.Tirol 0.106476 0.040283 2.643 0.008
L1.Vorarlberg -0.059082 0.034633 -1.706 0.088
L1.Wien 0.055382 0.063883 0.867 0.386
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064367 0.109814 0.586 0.558
L1.Burgenland -0.033470 0.073812 -0.453 0.650
L1.Kärnten 0.047799 0.039281 1.217 0.224
L1.Niederösterreich -0.171600 0.154309 -1.112 0.266
L1.Oberösterreich 0.384352 0.148201 2.593 0.010
L1.Salzburg 0.287799 0.078706 3.657 0.000
L1.Steiermark 0.106418 0.102977 1.033 0.301
L1.Tirol 0.313697 0.083466 3.758 0.000
L1.Vorarlberg 0.025009 0.071759 0.349 0.727
L1.Wien -0.017718 0.132364 -0.134 0.894
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190155 0.027228 6.984 0.000
L1.Burgenland 0.090049 0.018301 4.920 0.000
L1.Kärnten -0.008463 0.009739 -0.869 0.385
L1.Niederösterreich 0.264140 0.038260 6.904 0.000
L1.Oberösterreich 0.126732 0.036746 3.449 0.001
L1.Salzburg 0.047735 0.019515 2.446 0.014
L1.Steiermark 0.016790 0.025533 0.658 0.511
L1.Tirol 0.094284 0.020695 4.556 0.000
L1.Vorarlberg 0.059272 0.017792 3.331 0.001
L1.Wien 0.120342 0.032819 3.667 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109054 0.027881 3.911 0.000
L1.Burgenland 0.044587 0.018740 2.379 0.017
L1.Kärnten -0.016106 0.009973 -1.615 0.106
L1.Niederösterreich 0.193679 0.039178 4.944 0.000
L1.Oberösterreich 0.293470 0.037627 7.799 0.000
L1.Salzburg 0.115237 0.019983 5.767 0.000
L1.Steiermark 0.100228 0.026145 3.833 0.000
L1.Tirol 0.116253 0.021191 5.486 0.000
L1.Vorarlberg 0.070738 0.018219 3.883 0.000
L1.Wien -0.027423 0.033606 -0.816 0.414
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129441 0.050565 2.560 0.010
L1.Burgenland -0.051571 0.033987 -1.517 0.129
L1.Kärnten -0.040185 0.018087 -2.222 0.026
L1.Niederösterreich 0.170939 0.071052 2.406 0.016
L1.Oberösterreich 0.138299 0.068240 2.027 0.043
L1.Salzburg 0.286120 0.036241 7.895 0.000
L1.Steiermark 0.034463 0.047417 0.727 0.467
L1.Tirol 0.163830 0.038432 4.263 0.000
L1.Vorarlberg 0.103985 0.033042 3.147 0.002
L1.Wien 0.066951 0.060948 1.098 0.272
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060649 0.040104 1.512 0.130
L1.Burgenland 0.038241 0.026956 1.419 0.156
L1.Kärnten 0.050602 0.014345 3.527 0.000
L1.Niederösterreich 0.225121 0.056353 3.995 0.000
L1.Oberösterreich 0.281894 0.054122 5.208 0.000
L1.Salzburg 0.050736 0.028743 1.765 0.078
L1.Steiermark -0.006585 0.037607 -0.175 0.861
L1.Tirol 0.149960 0.030481 4.920 0.000
L1.Vorarlberg 0.071279 0.026206 2.720 0.007
L1.Wien 0.079017 0.048339 1.635 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179143 0.047940 3.737 0.000
L1.Burgenland -0.005880 0.032223 -0.182 0.855
L1.Kärnten -0.061118 0.017148 -3.564 0.000
L1.Niederösterreich -0.083508 0.067364 -1.240 0.215
L1.Oberösterreich 0.192264 0.064698 2.972 0.003
L1.Salzburg 0.056974 0.034359 1.658 0.097
L1.Steiermark 0.230887 0.044955 5.136 0.000
L1.Tirol 0.493717 0.036437 13.550 0.000
L1.Vorarlberg 0.049443 0.031326 1.578 0.114
L1.Wien -0.049586 0.057784 -0.858 0.391
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161526 0.055045 2.934 0.003
L1.Burgenland -0.011009 0.036999 -0.298 0.766
L1.Kärnten 0.066005 0.019690 3.352 0.001
L1.Niederösterreich 0.200910 0.077348 2.597 0.009
L1.Oberösterreich -0.061784 0.074287 -0.832 0.406
L1.Salzburg 0.215644 0.039452 5.466 0.000
L1.Steiermark 0.114057 0.051618 2.210 0.027
L1.Tirol 0.076694 0.041838 1.833 0.067
L1.Vorarlberg 0.124407 0.035970 3.459 0.001
L1.Wien 0.115722 0.066349 1.744 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.354851 0.031990 11.093 0.000
L1.Burgenland 0.006021 0.021502 0.280 0.779
L1.Kärnten -0.023570 0.011443 -2.060 0.039
L1.Niederösterreich 0.223518 0.044952 4.972 0.000
L1.Oberösterreich 0.175838 0.043172 4.073 0.000
L1.Salzburg 0.047522 0.022928 2.073 0.038
L1.Steiermark -0.018157 0.029998 -0.605 0.545
L1.Tirol 0.108788 0.024314 4.474 0.000
L1.Vorarlberg 0.073283 0.020904 3.506 0.000
L1.Wien 0.053151 0.038559 1.378 0.168
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041119 0.151984 0.191335 0.157077 0.125039 0.113240 0.065945 0.225621
Kärnten 0.041119 1.000000 -0.002567 0.129676 0.041488 0.096234 0.429786 -0.053119 0.101498
Niederösterreich 0.151984 -0.002567 1.000000 0.337503 0.154944 0.300692 0.110642 0.183596 0.327233
Oberösterreich 0.191335 0.129676 0.337503 1.000000 0.232144 0.333480 0.172672 0.172384 0.264371
Salzburg 0.157077 0.041488 0.154944 0.232144 1.000000 0.146559 0.126737 0.149014 0.136415
Steiermark 0.125039 0.096234 0.300692 0.333480 0.146559 1.000000 0.153248 0.140828 0.080420
Tirol 0.113240 0.429786 0.110642 0.172672 0.126737 0.153248 1.000000 0.114824 0.154721
Vorarlberg 0.065945 -0.053119 0.183596 0.172384 0.149014 0.140828 0.114824 1.000000 0.007291
Wien 0.225621 0.101498 0.327233 0.264371 0.136415 0.080420 0.154721 0.007291 1.000000